﻿using System;
using System.Collections.Generic;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EndtoEndSilverlightDemo.Tests
{
    [TestClass]
    public class IntegrationTestingWithAFulentInterface : SilverlightTest
    {
        [TestMethod, Asynchronous]
        public void When_searching_for_products_starting_with_the_letter_s_nine_products_should_be_displayed()
        {
            EndToEndSilverlightDemo.Page pageUnderTest = new EndToEndSilverlightDemo.Page();
            IPageTestDriver testDriver = pageUnderTest;
            
            using(UITestHelper ui = this.CreateUiTestHelper(pageUnderTest))
            {
                ui.Exec(testDriver.ClearLocalStorage);                
                
                ui.Exec(delegate { testDriver.TypeSearchPrefix("s"); });                
                
                ui.Exec(testDriver.ClickSearchButton);                
                
                ui.WaitUntil(testDriver.WebserviceHasReturnedData).IsTrue();                
                
                ui.Exec(delegate { Assert.AreEqual(9, testDriver.DisplayedProductRows); }); 

            }
        }
    }
}
